home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 8 code / TValidText / UTest.p < prev    next >
Encoding:
Text File  |  1991-10-09  |  8.9 KB  |  347 lines  |  [TEXT/MPS ]

  1. {*******************************************************************************
  2. UTest.p
  3.     This file describes the classes used in the Test program itself..
  4.  *******************************************************************************}
  5.  
  6. UNIT UTest;
  7.  
  8. INTERFACE
  9.     USES
  10.         { • MacApp }
  11.         UMacApp,
  12.  
  13.         { • Building Blocks }
  14.         UDialog,
  15.         UPrinting,
  16.  
  17.         { • Implementation Use }
  18.         Packages,
  19.         Resources,
  20.         Script,
  21.         UValidText,
  22.         UDateTimeText;
  23.  
  24.     {--------------------------------------------------------------------------}
  25.     
  26.     CONST
  27.         kSignature        = 'demo';    { Application signature}
  28.         kFileType        = 'dmo1';    { signature of created documents }
  29.         
  30.         kDialogWindowID    =  2001;    { dialog window's resource ID }
  31.         kDialogViewID    =  2002;    { dialog view's resource ID }
  32.         kDialogViewSIG    = 'DLOG';    { dialog view resource's signature }
  33.         kCancelViewSIG    = 'CNCL';    { cancel button's view resource's sig }
  34.         
  35.         cEnterDateTime    = 3000;        { show date/time dialog }
  36.         
  37.     {--------------------------------------------------------------------------}
  38.  
  39.     TYPE
  40.         TTestApplication = OBJECT (TApplication)
  41.             PROCEDURE TTestApplication.ITestApplication(
  42.                                     itsMainFileType:    OSType);
  43.             { Initializes the application and globals. }
  44.             
  45.             FUNCTION  TTestApplication.DoMenuCommand(
  46.                                     aCmdNumber:            CmdNumber)
  47.                                     : TCommand;
  48.                                     OVERRIDE;
  49.                                     
  50.             PROCEDURE TTestApplication.DoSetupMenus;
  51.                                     OVERRIDE;
  52.                                     
  53.             PROCEDURE TTestApplication.OpenNew(
  54.                                     itsCmdNumber:         CmdNumber);
  55.                                     OVERRIDE;
  56.             END;  { TTestApplication }
  57.         
  58.         TFixedPopup = OBJECT(TPopup)
  59.             PROCEDURE TFixedPopup.AdjustBotRight;
  60.                                     OVERRIDE;
  61.                 { This override leaves the right-hand edge of the popup alone. }
  62.             END;  { TFixedPopup }
  63.         
  64.         TTestDialog = OBJECT(TDialogView)
  65.             PROCEDURE TTestDialog.DoChoice(
  66.                                     origView:            TView;
  67.                                     itsChoice:            INTEGER);
  68.                                     OVERRIDE;
  69.                 { This routine updates either gDefaultDateForm or the 'DATE'
  70.                     view's fDateForm field, depending on which of its popup
  71.                     menu control subviews was selected. }
  72.             END;  { TTestDialog }
  73.  
  74.     {--------------------------------------------------------------------------}
  75.     IMPLEMENTATION
  76.     {--------------------------------------------------------------------------}
  77.  
  78.     PROCEDURE TTestApplication.ITestApplication(
  79.                             itsMainFileType:    OSType);
  80.         VAR
  81.             dummy:            BOOLEAN;
  82.  
  83.         BEGIN
  84.         IApplication(itsMainFileType);
  85.  
  86.         { So the linker doesn't dead strip class info }
  87.         IF gDeadStripSuppression
  88.         THEN
  89.             BEGIN
  90.             dummy := Member(TObject(NIL), TDateEditText);
  91.             dummy := Member(TObject(NIL), TTimeEditText);
  92.             dummy := Member(TObject(NIL), TFixedPopup);
  93.             dummy := Member(TObject(NIL), TTestDialog);
  94.             END;
  95.         END;  { ITestApplication }
  96.  
  97.     {--------------------------------------------------------------------------}
  98.  
  99.     FUNCTION TTestApplication.DoMenuCommand(
  100.                             aCmdNumber:            CmdNumber)
  101.                             : TCommand;
  102.                             OVERRIDE;
  103.     
  104.         VAR
  105.             theWindow:        TWindow;
  106.             theDialog:        TDialogView;
  107.             cancelled:        BOOLEAN;
  108.             oldTimeCycle:    Byte;
  109.             h:                Intl0Hndl;
  110.         
  111.         BEGIN
  112.         DoMenuCommand := gNoChanges;
  113.         
  114.         CASE aCmdNumber OF
  115.             cEnterDateTime:
  116.                 BEGIN
  117.                 { put up the demo dialog }
  118.                 theWindow := NewTemplateWindow(kDialogWindowID, NIL);
  119.                 FailNil(theWindow);
  120.                 theDialog := TDialogView(theWindow.FindSubView(kDialogViewSIG));
  121.                 FailNil(theDialog);
  122.             
  123.                 { save current time cycle }
  124.                 h := Intl0Hndl(IUGetIntl(0));
  125.                 FailNil(h);
  126.                 oldTimeCycle := h^^.timeCycle;
  127.                 
  128.                 theDialog.SelectEditText('DATE', TRUE);
  129.                 cancelled := (theDialog.PoseModally = kCancelViewSIG);
  130.                 theWindow.Close;
  131.             
  132.                 { restore the saved time cycle }
  133.                 h := Intl0Hndl(IUGetIntl(0));
  134.                 FailNil(h);
  135.                 h^^.timeCycle := oldTimeCycle;
  136.                 END;  { cEnterDateTime }
  137.     
  138.             OTHERWISE
  139.                 DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  140.             END;  { case }
  141.         END;  { DoMenuCommand }
  142.  
  143.     {--------------------------------------------------------------------------}
  144.  
  145.     PROCEDURE TTestApplication.DoSetupMenus;
  146.                             OVERRIDE;
  147.         BEGIN
  148.         INHERITED DoSetupMenus;
  149.         
  150.         Enable(cEnterDateTime, TRUE);
  151.         END;  { DoSetupMenus }
  152.  
  153.     {--------------------------------------------------------------------------}
  154.                                     
  155.     PROCEDURE TTestApplication.OpenNew(
  156.                             itsCmdNumber:         CmdNumber);
  157.                             OVERRIDE;
  158.         { This OVERRIDE is the official way to prevent the opening of a new,
  159.             untitled document whenever the program starts (see UMacApp.p, in
  160.             the defintion of TApplication.OpenNew().) }
  161.         BEGIN
  162.         IF (itsCmdNumber <> cFinderNew)
  163.         THEN
  164.             INHERITED OpenNew(itsCmdNumber);
  165.         END;  { OpenNew }
  166.  
  167.     {--------------------------------------------------------------------------}
  168.     
  169.     PROCEDURE TTestDialog.DoChoice(
  170.                             origView:            TView;
  171.                             itsChoice:            INTEGER);
  172.                             OVERRIDE;
  173.         { This routine handles the interactions between the various dialog
  174.             controls.  It's big, it's ugly, it uses a case statement — but
  175.             it works, OK? }
  176.         
  177.         VAR
  178.             curItem:        INTEGER;
  179.             theDateForm:    INTEGER;
  180.             datePopup:        TPopup;
  181.             globalPopup:    TPopup;
  182.             dateView:        TDateEditText;
  183.             timeView:        TTimeEditText;
  184.             
  185.         {----------------------------------------------------------------------}
  186.         
  187.         PROCEDURE ToggleTimeCycle;
  188.             VAR
  189.                 h:                Intl0Hndl;
  190.             
  191.             BEGIN
  192.             h := Intl0Hndl(IUGetIntl(0));
  193.             FailNil(h);
  194.             
  195.             WITH h^^ DO
  196.                 BEGIN
  197.                 IF (timeCycle = 0)
  198.                 THEN
  199.                     timeCycle := 255    { 12-hour cycle }
  200.                 ELSE
  201.                     timeCycle := 0;        { 24-hour cycle }
  202.                 END;  { with h^^ }
  203.             END;  { ToggleTimeCycle }
  204.             
  205.         {----------------------------------------------------------------------}
  206.         
  207.         BEGIN  { DoChoice }
  208.         CASE itsChoice OF
  209.             mPopupHit:
  210.                 BEGIN
  211.                 { get a number of sub-view references }
  212.                 datePopup := TPopup(FindSubView('pDAT'));
  213.                 FailNil(datePopup);
  214.                 
  215.                 globalPopup := TPopup(FindSubView('pGLO'));
  216.                 FailNil(globalPopup);
  217.                 
  218.                 dateView := TDateEditText(FindSubView('DATE'));
  219.                 FailNil(dateView);
  220.                 
  221.                 IF (origView = datePopup)
  222.                 THEN
  223.                     BEGIN
  224.                     { change the fDateForm field of the TDateEditText item }
  225.                     curItem := datePopup.GetCurrentItem;
  226.                     
  227.                     CASE curItem OF
  228.                         1..3:
  229.                             theDateForm := curItem - 1;        { <= [0..2] }
  230.                         
  231.                         OTHERWISE
  232.                             theDateForm := kDefDateForm;    { <= 255 }
  233.                         END;  { case curItem }
  234.                     
  235.                     dateView.SetDateForm(theDateForm, kRedraw);
  236.                     dateView.SetSelection(0, maxint, kRedraw);
  237.                     END
  238.                 ELSE IF (origView = globalPopup)
  239.                 THEN
  240.                     BEGIN
  241.                     { change the value of the gDefaultDateForm global }
  242.                     SetDefaultDateForm(DateForm(globalPopup.GetCurrentItem
  243.                                                 - 1));
  244.                     
  245.                     { update the dateView, if it depends on gDefaultDateForm }
  246.                     IF (dateView.GetDateForm = kDefDateForm)
  247.                     THEN
  248.                         BEGIN
  249.                         dateView.UpdateText(kRedraw);
  250.                         dateView.SetSelection(0, maxint, kRedraw);
  251.                         END;
  252.                     END;
  253.                 END;  { mPopupHit }
  254.                 
  255.             mCheckBoxHit:
  256.                 BEGIN
  257.                 { get a reference to the 'TIME' time edit text item }
  258.                 timeView := TTimeEditText(FindSubView('TIME'));
  259.                 FailNil(timeView);
  260.                     
  261.                 { get a reference to the 'DATE' date edit text item }
  262.                 dateView := TDateEditText(FindSubView('DATE'));
  263.                 FailNil(dateView);
  264.                 
  265.                 IF (origView = FindSubView('HOUR'))
  266.                 THEN
  267.                     BEGIN
  268.                     { toggle the time cycle (12-hours or 24-hours) }
  269.                     ToggleTimeCycle;
  270.                 
  271.                     timeView.UpdateText(kRedraw);
  272.                     timeView.SetSelection(0, maxint, kRedraw);
  273.                     END
  274.                 ELSE IF (origView = FindSubView('SECS'))
  275.                 THEN
  276.                     BEGIN
  277.                     { toggle 'want secs' }
  278.                     timeView.SetWantSeconds((NOT timeView.GetWantSeconds),
  279.                                             kRedraw);
  280.                     timeView.SetSelection(0, maxint, kRedraw);
  281.                     END
  282.                 ELSE IF (origView = FindSubView('Vlid'))
  283.                 THEN
  284.                     BEGIN
  285.                     { toggle strict validation }
  286.                     timeView.SetStrict(
  287.                                     TCheckBox(origView).IsOn);
  288.                     
  289.                     dateView.SetStrict(
  290.                                     TCheckBox(origView).IsOn);
  291.                     END
  292.                 ELSE IF (origView = FindSubView('rqur'))
  293.                 THEN
  294.                     BEGIN
  295.                     { toggle fRequire field }
  296.                     timeView.SetRequired(
  297.                                     TCheckBox(origView).IsOn);
  298.                     
  299.                     dateView.SetRequired(
  300.                                     TCheckBox(origView).IsOn);
  301.                     END;
  302.                 END;  { mCheckBoxHit }
  303.             END;  { case itsChoice }
  304.         
  305.         INHERITED DoChoice(origView, itsChoice);
  306.         END;  { DoChoice }
  307.  
  308.     {--------------------------------------------------------------------------}
  309.  
  310.     PROCEDURE TFixedPopup.AdjustBotRight;
  311.                             OVERRIDE;
  312.     
  313.         VAR
  314.             numItems:            INTEGER;
  315.             newHeight:            INTEGER;
  316.             newWidth:            INTEGER;
  317.             savedPort:            GrafPtr;
  318.             theFontInfo:        FontInfo;
  319.     
  320.         BEGIN
  321.         IF fMenuHandle <> NIL THEN
  322.             BEGIN
  323.             CalcMenuSize(fMenuHandle);
  324.             numItems := CountMItems(fMenuHandle);
  325.             (* newWidth := fMenuHandle^^.menuWidth +
  326.                            fItemOffset +
  327.                            fInset.left +
  328.                            fInset.right +
  329.                            3;
  330.             *)
  331.     
  332.             GetPort(savedPort);
  333.             SetPort(gWorkPort);
  334.             SetPortTextStyle(gSystemStyle);
  335.             GetFontInfo(theFontInfo);
  336.             SetPort(savedPort);
  337.     
  338.             WITH theFontInfo DO
  339.                 newHeight := ascent + descent + leading + fInset.top + fInset.bottom + 3;
  340.     
  341.             (* Resize(newWidth, newHeight, kDontRedraw); *)
  342.             Resize(fSize.h, newHeight, kDontRedraw);
  343.             END;
  344.         END;  { AdjustBotRight }
  345.  
  346. END.  { UTest.p }
  347.